42 Vowel Count 7 kyu


Posted by mijouhsieh on 2024-01-04

7 kyu Vowel Count

題目說明:

函式帶入字串判斷有幾個母音(a,e,i,o,u)

code
export class Kata {
  static getCount(str: string): number {
    //code
    const lowerCaseStr = str.trim().toLowerCase();
    const regex = /[aeiou]/g;
    const matches = lowerCaseStr.match(regex);

    if (matches) {
      return matches.length;
    } else {
      return 0;
    }
  }
}

#TypeScript #string.match() #RegEx







Related Posts

DAY41:Equal Sides Of An Array

DAY41:Equal Sides Of An Array

AWS Solutions Architect - Associate (SAA) 學習計畫與備考心得: Module 1

AWS Solutions Architect - Associate (SAA) 學習計畫與備考心得: Module 1

Web開發學習筆記23 — 開始使用數據庫(Mongoose)

Web開發學習筆記23 — 開始使用數據庫(Mongoose)


Comments